package cc.xsubj.engine;

import org.newdawn.slick.geom.Rectangle;

import cc.xsubj.engine.entity.Entity;

public class SimpleFollowCamera extends Camera
{

    public SimpleFollowCamera(World world, Entity follow, int renderWidth,
            int renderHeight, Rectangle bounds)
    {
        super(world, follow, renderWidth, renderHeight);
        this.viewport = new Rectangle(cameraX, cameraY, renderWidth, renderHeight);
        this.bounds = bounds;
    }

    @Override
    protected void setCamera()
    {
        cameraX = follow.x + follow.width/2 - renderWidth/2;
        cameraX = Math.max(cameraX, bounds.getMinX());
        cameraX = Math.min(cameraX, bounds.getMaxX());
        
        cameraY = follow.y + follow.height/2 - renderHeight/2;
        cameraY = Math.max(cameraY, bounds.getMinY());
        cameraY = Math.min(cameraY, bounds.getMaxY());
        
        viewport.setBounds(cameraX, cameraY, renderWidth, renderHeight);
    }

}
